/**
 * @class ExtGames.Deck
 * @param {Array} cards An array of cards to initialise the deck with
 * Represents the deck of all non-dealt cards
 */
ExtGames.CardHolder = function(config) {
  var config = config || {};
  
  ExtGames.CardHolder.superclass.constructor.call(this, config);
      
  this.addEvents(
		    'carddropped'
		  );
};

Ext.extend(ExtGames.CardHolder, Ext.Container, {
  

  onRender: function(ct, position) {
    
    ExtGames.CardHolder.superclass.onRender.apply(this, arguments);
  },
  
  
  	initializeDropTarget: function() {
	    //local reference to use in dropTarget config
	    var stack = this;
	    
	    this.dropTarget = new Ext.dd.DropTarget(this.getEl(), {
	      notifyOver: function(source, e, data) {
	        if (stack.dropAllowed(data.card)) {
	          return Ext.dd.DropTarget.prototype.dropAllowed;
	        } else {
	          return Ext.dd.DropTarget.prototype.dropNotAllowed;
	        };
	      },
	      
	      notifyDrop: function(source, e, data) {
	        if (stack.dropAllowed(data.card)) {
	          return stack.fireEvent('carddropped', stack, data.card, e);
	        } else {
	          return false;
	        }
	      }
	    });
	},
	  
	getCards: function() {
	  	if (this.items && this.items.items) {
	  		return this.items.items;
	  	}
	  	return [];
  	},
  
  	destroyCards: function() {
  		if (this.items && this.items.items) {
	  		while (this.items.items.length > 0) {
	  			this.remove(this.items.items[0]);
	  		}
	  	}
  	},
  	
  	getTopCard: function() {
	    return this.items.items[this.items.length - 1];
	}
  
  
});